package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.SpringLambEntity;
import io.renren.modules.generator.service.SpringLambService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 春羔净利润
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-01 21:59:01
 */
@RestController
@RequestMapping("springlamb")
public class SpringLambController {
	@Autowired
	private SpringLambService springLambService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("springlamb:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SpringLambEntity> springLambList = springLambService.queryList(query);
		int total = springLambService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(springLambList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("springlamb:info")
	public R info(@PathVariable("id") Long id){
		SpringLambEntity springLamb = springLambService.queryObject(id);
		
		return R.ok().put("springLamb", springLamb);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("springlamb:save")
	public R save(@RequestBody SpringLambEntity springLamb){
		springLambService.save(springLamb);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("springlamb:update")
	public R update(@RequestBody SpringLambEntity springLamb){
		springLambService.update(springLamb);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("springlamb:delete")
	public R delete(@RequestBody Long[] ids){
		springLambService.deleteBatch(ids);
		
		return R.ok();
	}

	@RequestMapping("/timelist")
	@RequiresPermissions("springlamb:list")
	public R timelist(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		System.out.println("得到的参数"+params+"/n下一个参数"+query);
		List<SpringLambEntity> animalpriceList = springLambService.timeList(query);
		int total = springLambService.timeTotal(query);

		PageUtils pageUtil = new PageUtils(animalpriceList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}
	
}
